import collections
class DetectSquares(object):

    def __init__(self):
        self.d = collections.defaultdict(int)
        self.duijiao1 = collections.defaultdict(set)
        self.duijiao2 = collections.defaultdict(set)

    def add(self, point):
        self.d[tuple(point)] += 1
        self.duijiao1[point[1] - point[0]].add(tuple(point))
        self.duijiao2[point[0] + point[1]].add(tuple(point))


    def count(self, point):
        x = point[0]
        y = point[1]
        ans = 0
        if self.duijiao1[y - x]:
            for ux, uy in self.duijiao1[y - x]:
                if (ux, uy) != (x, y):
                    ans += self.d[(ux, uy)] * self.d[(ux, y)] * self.d[x, uy]
        if self.duijiao2[x + y]:
            for ux, uy in self.duijiao2[x + y]:
                if (ux, uy) != (x, y):
                    ans += self.d[(ux, uy)] * self.d[(ux, y)] * self.d[x, uy]
        return ans
